package com.lianboke.link.ad.activity;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ProgressBar;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.Views.MyListView;
import com.lianboke.link.ad.VolleyUtils.HttpCallBack;
import com.lianboke.link.ad.VolleyUtils.HttpUtil;
import com.lianboke.link.ad.adapter.AccountRecordAdapter;
import com.lianboke.link.ad.app.MyApplication;
import com.lianboke.link.ad.beans.AccountRecordModel;
import com.lianboke.link.ad.common.CommonParams;
import com.lianboke.link.ad.utils.DeviceUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;


/**
 * 提现记录
 */
public class UserTiXianRecordActivity extends BaseActivity {

    @BindView(R.id.lv_order_1)
    public MyListView lv_order_1;

    @BindView(R.id.rv_swipe_refresh)
    public SwipeRefreshLayout rv_swipe_refresh;

    @BindView(R.id.loading_progress)
    public ProgressBar loading_progress;

    @BindView(R.id.view_empty)
    public View view_empty;


    private List<AccountRecordModel> accountRecordDatas = new ArrayList<AccountRecordModel>();
    private AccountRecordAdapter accountRecordAdapter;//类型任务数据适配器


    @Override
    public int getContentViewId() {
        return R.layout.activity_user_ti_xian_record;
    }

    @Override
    public void initActivityParams(Bundle savedInstanceState) {
        setTitleBackShow(true);
        setTitleContent("提款记录");

        //设置数据适配器
        accountRecordAdapter = new AccountRecordAdapter(actContext);
        lv_order_1.setAdapter(accountRecordAdapter);


        //初始化为非刷新状态
        rv_swipe_refresh.setRefreshing(false);
        rv_swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener(){
            @Override
            public void onRefresh() {
                //任务列表刷新
                rv_swipe_refresh.setRefreshing(true);
                getUserAccountRecordDatasByNetwork();
            }
        });

        //获取任务列表数据
        showLoadingProgress();
        getUserAccountRecordDatasByNetwork();
    }

    /**
     * 显示加载框
     */
    private void showLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!= View.VISIBLE){
            loading_progress.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏家在狂
     */
    private void hideLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!=View.GONE){
            loading_progress.setVisibility(View.GONE);
        }
    }
    /**
     * 获取任务别表
     */
    public void getUserAccountRecordDatasByNetwork(){
        HashMap<String,String> params = new HashMap<String,String>();
        params.put("deviceid", DeviceUtils.getImei(appContext));
        params.put("version",DeviceUtils.getVersionName(actContext));
        params.put("nettypename",DeviceUtils.getDeviceAc());
        params.put("city", MyApplication.strCity);
        HttpUtil.getInstance().request_get(CommonParams.URL_WEB_SUBMIT_DRAW_MONEY, params, new HttpCallBack<List<AccountRecordModel>>() {
            @Override
            public void onSuccess(List<AccountRecordModel> data) {
                hideLoadingProgress();
                rv_swipe_refresh.setRefreshing(false);
                if(data!=null && !data.isEmpty()){
                    hideEmptyDatasView();
                    if (accountRecordDatas==null) {
                        accountRecordDatas = new ArrayList<AccountRecordModel>();
                    }
                    accountRecordDatas.clear();
                    accountRecordAdapter.setOrderDatas(accountRecordDatas);
                }else{
                    showEmptyDatasView();
                }
            }

            @Override
            public void onFail(String msg) {
                rv_swipe_refresh.setRefreshing(false);
                hideLoadingProgress();
                showEmptyDatasView();
            }
        });
    }

    /**
     * 显示空数据view
     */
    public void showEmptyDatasView(){
        if(rv_swipe_refresh!=null){
            rv_swipe_refresh.setVisibility(View.GONE);
        }
        if(view_empty!=null){
            view_empty.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏空数据view
     */
    public void hideEmptyDatasView(){
        if(rv_swipe_refresh!=null){
            rv_swipe_refresh.setVisibility(View.VISIBLE);
        }
        if(view_empty!=null){
            view_empty.setVisibility(View.GONE);
        }
    }
}
